package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YearDTO;
import com.CST.dto.ys.YsBusinessTargetDTO;
import com.CST.entity.ys.YsBusinessTarget;
import com.CST.service.ys.YsBusinessTargetService;
import com.CST.vo.ys.YsBusinessTargetRecordVO;
import com.CST.vo.ys.YsBusinessTargetVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 业务量配套指标
 *
 * @author cw
 * @since 2023-05-06
 */
@RestController
@RequestMapping("/ysBusinessTarget")
@Api(tags = "业务量配套指标")
public class YsBusinessTargetController {

    @Autowired
    private YsBusinessTargetService targetService;

    @ApiOperation("新增")
    @PostMapping("/insertYsBusinessTarget")
    public ResultObject<Integer> insertYsBusinessTarget(@RequestBody YsBusinessTarget ysBusinessTarget){
        return ResultObject.success(targetService.insertYsBusinessTarget(ysBusinessTarget));
    }

    @ApiOperation("编辑")
    @PostMapping("/updateYsBusinessTarget")
    public ResultObject<Integer> updateYsBusinessTarget(@RequestBody YsBusinessTarget ysBusinessTarget){
        return ResultObject.success(targetService.updateYsBusinessTarget(ysBusinessTarget));
    }

    @ApiOperation("编辑回显数据")
    @GetMapping("/getInfoByNum/{id}")
    public ResultObject<YsBusinessTargetVO> getInfoByNum(@PathVariable Long id){
        return ResultObject.success(targetService.selectInfoById(id));
    }

    @ApiOperation("删除")
    @GetMapping("/deleteYsBusinessTarget/{id}")
    public ResultObject<Integer> deleteYsBusinessTarget(@PathVariable Long id){
        return ResultObject.success(targetService.deleteYsBusinessTarget(id));
    }

    @ApiOperation("查询")
    @PostMapping("/getYsBusinessTargetList")
    public ResultObject<PageInfo<YsBusinessTargetVO>> getYsBusinessTargetList(@RequestBody YsBusinessTargetDTO ysBusinessTargetDTO){
        return ResultObject.success(targetService.getYsBusinessTargetList(ysBusinessTargetDTO));
    }

    @ApiOperation("发布数据")
    @PostMapping("/releaseData")
    public ResultObject<Boolean> releaseData(@RequestBody YsBusinessTargetDTO ysBusinessBudgetDto){
        return ResultObject.success(targetService.releaseData(ysBusinessBudgetDto));
    }

    @ApiOperation("继承")
    @PostMapping("/extendsData")
    public ResultObject<Boolean> extendsData(@RequestBody YearDTO dto){
        return ResultObject.success(targetService.extendsData(dto));
    }

    @ApiOperation("撤销")
    @GetMapping("/revokeRecord/{id}")
    public ResultObject<Boolean> revokeRecord(@PathVariable Long id){
        return ResultObject.success(targetService.revokeRecord(id));
    }

    @ApiOperation("查询修订记录")
    @PostMapping("/getRecordList")
    public ResultObject<PageInfo<YsBusinessTargetRecordVO>> getRecordList(@RequestBody YsBusinessTargetDTO ysBusinessTargetDTO){
        return ResultObject.success(targetService.selectRecordList(ysBusinessTargetDTO));
    }

    @PostMapping("/download_ex")
    @ApiOperation("下载模板文件，必要参数HttpServletResponse response,")
    public void download(HttpServletResponse response) {
        targetService.download(response);
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsBusinessTarget")
    public void exportExcelYsBusinessTarget(HttpServletResponse response, @RequestBody YsBusinessTargetDTO dto) {
        targetService.exportExcelYsBusinessTarget(response, dto);
    }

    @ApiOperation("导入")
    @PostMapping("/import")
    public void importExcelYsBusinessTarget(MultipartFile file) {
        targetService.importExcelYsBusinessTarget(file);
    }
}
